﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using Drifter.Core;

namespace DrifterTest
{
    [TestClass]
    public class FieldListTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
        }



        [TestMethod]
        public void TestMethod2()
        {

            //            string xml =
            //             @"<configuration>
            //                  <fields>
            //                      <field name='Field1'  source='Main' pos='12345' length='12345' enabled='tRue'/>
            //                      <field name='Field2'  source='Main'  enabled='True'/>
            //                      <field name='Flexfield'  source='Main'  flexible='true'/>
            //                  </fields>
            //               </configuration>";


            string xml =
             @"<fields>
                    <field name='Field1'  source='Main' pos='12345' length='12345' enabled='tRue'/>
                    <field name='Field2'  source='Main'  enabled='True'/>
                    <field name='Flexfield'  source='Main'  flexible='true'/>
               </fields>";


            File.WriteAllText("testFields.xml", xml);

            FieldList list = new FieldList();
            list.LoadFromFile("testFields.xml");

            Assert.AreEqual(3, list.Count());
            Assert.AreEqual(12345, list.ToArray()[0].Pos);
            Assert.AreEqual(true, list.ToArray()[0].Enabled);
            Assert.AreEqual(null, list.ToArray()[1].Pos);
            Assert.AreEqual(true, list.ToArray()[2].Flexible);
        }

    }
}
